﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Logic.Functions;
using System.Reflection;

namespace Logic
{
    public class ResourceManager
    {
        private static Dictionary<String, IFunction> activationFunctions;

        private ResourceManager()
        {
        }

        public static void Init()
        {
            InitActivationFunctions();
            // tu beda kolejne inicjalizacje
        }

        private static void InitActivationFunctions()
        {
            activationFunctions = new Dictionary<string, IFunction>();

            Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .Where(type => type.GetInterfaces()
                    .Count(i => i.Equals(typeof(IFunction))) > 0)
                .AsParallel()
                .ForAll(type => { IFunction fun = (IFunction)Activator.CreateInstance(type); activationFunctions[fun.Symbol] = fun; });
        }

        public static IFunction GetActivationFunctionBySymbol(String symbol)
        {
            return activationFunctions[symbol];
        }

        public static IEnumerable<IFunction> GetActivationFunctions()
        {
            return activationFunctions.Values;
        }
    }
}
